package com.ugoodtech.mdcc.core.repository;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by Stone Shaw, 16/3/9
 */

import com.ugoodtech.mdcc.core.domain.GeneralCode;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

public interface GeneralCodeRepository extends PagingAndSortingRepository<GeneralCode, Long>, QueryDslPredicateExecutor<GeneralCode> {

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update GeneralCode h set h.deleted=true where h.id=:id")
    void delete(@Param("id") Long id);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update GeneralCode h set h.deleted=true where h.id in :ids")
    void delete(@Param("ids") Collection<Long> ids);

//    @Query("select c from GeneralCode c where c.category=:category and c.deleted=false order by c.orderNum asc ")
//    List<GeneralCode> findByCategory(@Param("category") Integer category);
//
//    @Query("select c from GeneralCode c where c.category=:category and c.nationCode=:nationCode and c.deleted=false order by c.orderNum asc")
//    List<GeneralCode> findByCategoryAndNationCode(@Param("category") Integer category, @Param("nationCode") String nationCode);


}
